package com.focus.xyz.union.cases.frontend;

import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.union.action.KeyWordAction;
import com.focus.xyz.core.common.listeners.TC;
import com.focus.xyz.core.utils.Constants;
import com.focus.xyz.core.utils.ExcelUtils;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.core.utils.prop.ConfigPropInfo;
import com.focus.xyz.union.data.InsDataBean;
import com.focus.xyz.union.data.InsDataService;
import com.focus.xyz.union.pages.frontend.FrontMenuList;
import com.focus.xyz.union.pages.frontend.tables.ProxyProdTable;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.*;

/**
 * Created by chenmeng on 2016/5/20.
 */
public class ProdScopePlatTest extends TC {
    private static transient Logger logger = LoggerFactory.getLogger(ProdScopePlatTest.class);

    private WebDriver driver;
    private KeyWordAction action;
    private ExcelUtils eu;

    @BeforeClass
    public void beforeClass() throws Exception{
        eu = new ExcelUtils(ConfigPropInfo.TEST_DATA_DIR + ConfigPropInfo.TEST_UNION_DATA_FILE);
        action.DelUnionFrontCookie();
    }


    @Parameters({"nodeUrl","browser","userName","password"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String nodeUrl,String browser,String userName,String password) throws Exception {
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        super.init(driver);
        action = new KeyWordAction(driver);
        action.LoginFront(userName,password);
    }


    @Parameters({"browser"})
    @AfterMethod(alwaysRun = true)
    public void tearDown(String browser) {
        try{
            super.quit();
            driver.quit();
        }catch (Exception e){
            ProcessUtil.closeBrowser(browser);
        }finally {

        }
    }


    @Parameters({"insDataIdx"})
    @Test(description = "校验产品范围、投放平台")
    public void PROD_SCOPE_PLAT_CHECK(String insDataIdx) throws Exception{
        FrontMenuList menuList = new FrontMenuList(driver,action);
        menuList.openMenu(Constants.U_F_TB_MENU);
        ProxyProdTable ptable = new ProxyProdTable(driver,action);
        if (!"1".equals(ptable.getProdCount())){
            action.fail("代理人已代理产品与后台设置产品数量不符");
        }
        if(2!=ptable.getRowCount()){
            action.fail("代理人已代理产品列表展示数与后台设置数量不一致");
        }
        InsDataBean bean = InsDataService.getInsDataById(insDataIdx);
        if(!bean.getProdName().equals(ptable.getProdName(bean.getProdName()))){
            action.fail("代理人已代理产品与后台设置产品名称不一致");
        }
    }

}
